home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MPW_TOOL / TOOLS / TOOLS_WI / ICON_8 / COMMON_F / LONG.C < prev    next >
Text File  |  1990-03-02  |  786b  |  50 lines

  1. /*
  2.  *  common.c -- functions common to several modules.
  3.  */
  4.  
  5. #include "::h:config.h"
  6. #include "::h:cpuconf.h"
  7. #include <ctype.h>
  8.  
  9. #if IntBits == 16
  10. /*
  11.  * Long strlen
  12.  */
  13.  
  14. long lstrlen(s)
  15. char *s;
  16. {
  17.     long l = 0;
  18.     while(*s++) l++;
  19.     return l;
  20. }
  21. #endif                    /* IntBits */
  22.  
  23. /* 
  24.  * Write a long string in int-sized chunks.
  25.  */
  26.  
  27. long longwrite(s,len,file)
  28. FILE *file;
  29. char *s;
  30. long len;
  31. {
  32.    long tally = 0;
  33.    int n = 0;
  34.    int leftover, loopnum;
  35.    char *p;
  36.  
  37.    leftover = len % MaxInt;
  38.    for (p = s, loopnum = len/MaxInt; loopnum; loopnum--) {
  39.        n = fwrite(p,sizeof(char),MaxInt,file);
  40.        tally += n;
  41.        p += MaxInt;
  42.    }
  43.    if (leftover)
  44.       n = fwrite(p,sizeof(char),leftover,file);
  45.    tally += n;
  46.    if (tally != len)
  47.       return -1;
  48.    else return tally;
  49.    }
  50.